<%@page import="org.ilead.iserve.service.manager.MessageManager"%>
<%@page import="java.util.Date"%>
<%@page import="org.ilead.iserve.model.PrivateMessage"%>
<%@page import="org.ilead.iserve.model.User"%>
<%@page import="org.ilead.iserve.constants.SessionKeyConstant"%>
<%@page import="java.util.Map"%>
<%@page import="org.ilead.iserve.service.manager.UserManager"%>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	Map<String,String[]> paramMap = request.getParameterMap();
	boolean isInvalid = false;
	
	if(paramMap.containsKey("content") && paramMap.containsKey("target")){
		try{
			int source = ((User)session.getAttribute(SessionKeyConstant.LOGIN_USER)).getId();
			String content = paramMap.get("content")[0];
			int target = Integer.parseInt(paramMap.get("target")[0]);
			PrivateMessage m = new PrivateMessage();
			m.setSource(source);
			m.setContent(content);
			m.setTarget(target);
			m.setSendTime(new Date());
			m.setReState(0);
			m.setSeState(0);
			MessageManager.getInstance().addPrivateMessage(m);
			isInvalid = false;
		}catch(Exception e){
			isInvalid = true;
		}
	}
	//AJAX
	response.setContentType("text/xml");
	response.setHeader("Cache-Control","no-stroe");
	response.setHeader("pragma","no-cache");
	response.setDateHeader("Expries",0);
	String message = "";
	if(isInvalid == true) {
		message = "invalid";
	}else{
		message = "validate";
	}
	response.getWriter().write("<msg>"+ message +"</msg>");
%>
